package cn.xgj.sfzy.service.impl;

import cn.xgj.sfzy.entity.RootUser;
import cn.xgj.sfzy.mapper.RootUserMapper;
import cn.xgj.sfzy.service.RootUserService;
import cn.xgj.sfzy.util.MD5Util;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName RootUserServiceImpl
 * @Description TODO
 * @Author xgj
 * @Date 2024年10月22日 下午4:20
 * @Version 1.0
 */
@Service
public class RootUserServiceImpl implements RootUserService {
    @Autowired
    private RootUserMapper rootUserMapper;
    @Override
    public RootUser login(String root_name, String root_password) {
//        对密码进行加密
        root_password = MD5Util.encode(root_name+root_password);
        return rootUserMapper.selectByUsernameAndPassword(root_name,root_password);
    }
    @Override
    public int add(RootUser rootUser) {
        return rootUserMapper.insert(rootUser);
    }

    @Override
    public int edit(RootUser rootUser) {
        return rootUserMapper.update(rootUser);
    }

    @Override
    public int remove(Integer id) {
        return rootUserMapper.delete(id);
    }

    @Override
    public List<RootUser> findAll(RootUser rootUser) {
        return rootUserMapper.find(rootUser);
    }

    @Override
    public RootUser findById(Integer id) {
        return rootUserMapper.findById(id);
    }

    @Override
    public PageInfo<RootUser> findByPage(Integer pageNum, Integer pageSize, RootUser rootUser) {
        PageHelper.startPage(pageNum,pageSize);
        List<RootUser> list = rootUserMapper.find(rootUser);
        PageInfo<RootUser> pageInfo=new PageInfo<RootUser>(list);
        return pageInfo;
    }
}
